<table class="table table-striped table-bordered table-hover">
    <?php if(empty($promotionList)){echo "<i>Hiện không có thiết lập khuyến mãi nào</i>";} else{ ?>
    <thead>
    <tr>
        <th>#</th>
        <th>Tên khuyến mãi</th>
        <th>Ngày bắt đầu</th>
        <th>Ngày kết thúc</th>
        <th>Lượt mua</th>
        <th>Trạng thái</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1; foreach($promotionList as $objPromotionList){ ?>
    <tr>
        <td><?php echo $i ?></td>
        <td><a><?php echo $objPromotionList->promotion_name ?></a></td>
        <td><?php if($objPromotionList->buying_bouts == 0){echo $objPromotionList->promotion_from;} else{echo "";} ?></td>
        <td><?php if($objPromotionList->buying_bouts == 0){echo $objPromotionList->promotion_to;} else{echo "";} ?></td>
        <td><?php if($objPromotionList->buying_bouts != 0){echo $objPromotionList->buying_bouts;} else{echo "";} ?></td>
        <td><?php if($objPromotionList->promotion_status == 1){echo "Hoạt động";} else{echo "Ngừng hoạt động";} ?></td>
        <td>
            <input type="hidden" id="hidAdminEditAdminPromotionID<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_id ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionName<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_name ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionStatus<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_status ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionFrom<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_from ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionTo<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_to ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionBuyingBouts<?php echo $i ?>" value="<?php echo $objPromotionList->buying_bouts ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionOtherPrograms<?php echo $i ?>" value="<?php echo $objPromotionList->other_programs ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionBuyingValue<?php echo $i ?>" value="<?php echo $objPromotionList->buying_value ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionGettingValue<?php echo $i ?>" value="<?php echo $objPromotionList->getting_value ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionDetailStyle<?php echo $i ?>" value="<?php echo $objPromotionList->detail_style ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionProductApply<?php echo $i ?>" value="<?php echo $objPromotionList->product_apply ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionPromotionStyle<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_style ?>">
            <input type="hidden" id="hidAdminEditAdminPromotionPromotionInform<?php echo $i ?>" value="<?php echo $objPromotionList->promotion_inform ?>">

            <a style='cursor: pointer' class='btn btn-warning btn-xs pull-right' onclick='setValueUpdateEditAdminPromotion($("#hidAdminEditAdminPromotionID<?php echo $i ?>").val()
            , $("#hidAdminEditAdminPromotionName<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionStatus<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionFrom<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionTo<?php echo $i ?>").val()
            , $("#hidAdminEditAdminPromotionBuyingBouts<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionOtherPrograms<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionBuyingValue<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionGettingValue<?php echo $i ?>").val()
            , $("#hidAdminEditAdminPromotionDetailStyle<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionProductApply<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionPromotionStyle<?php echo $i ?>").val(), $("#hidAdminEditAdminPromotionPromotionInform<?php echo $i ?>").val());'>
                <span class='glyphicon glyphicon-pencil'></span>
            </a>
            <a class='btn btn-danger btn-xs pull-right' onclick="deletePromotion('<?php echo $objPromotionList->promotion_id ?>')"><span class='glyphicon glyphicon-remove'></span></a>
        </td>
    </tr>
    <?php $i++; } ?>
    </tbody>
    <?php } ?>
</table>

<!-- input Edit Control Panel -->
<div class="light row" id="lightEditAdminPromotion" style="width: 80%; height: inherit; left: 19%; top: 11%;">
<div class="panel panel-default">
<div class="panel-heading">
    <h3 class="panel-title">Chỉnh Sửa Khuyến Mãi</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-12" style="margin: 3px;">
<div class="row" style="margin: 5px;">
    <div class="col-lg-1"><span style="color: red">* </span></div>
    <div class="col-lg-3">Tên khuyến mãi:</div>
    <div class="col-lg-8"><input id="txtEditPromotionName" class="form-control" type="text"></div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1"><span style="color: red">* </span></div>
    <div class="col-lg-3">Trạng thái hoạt động:</div>
    <div class="col-lg-8">
        <select class="form-control" id="slEditPromotionStatus" style="width: 85%">
            <option value="1">Hoạt động</option>
            <option value="0">Ngừng Hoạt động</option>
        </select>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1"><span style="color: red">* </span></div>
    <div class="col-lg-3">Đặt hạn áp dụng khuyến mãi:</div>
    <div class="col-lg-8">
        <div class="row" style="margin: 10px;">
            <div class="input-group">
                <input type="radio" id="radioEditDayApplyPromotion" onclick="$('#divEditDayApplyPromotion').show(); $('#radioEditBoutApplyPromotion').prop('checked', false); $('#divEditBoutApplyPromotion').hide();">
                <label> &nbsp Áp dụng theo ngày</label>
            </div><!-- /input-group -->
        </div>
        <div class="row" id="divEditDayApplyPromotion" style="display: none">
            <div class="col-lg-2" style="margin-top: 8px;">
                <span class="label label-default" style="padding: 10px; font-size: 13px;">Từ ngày: </span>
            </div>
            <div class="col-lg-4">
                <input class="form-control" type="date" id="dateEditPromotionFrom">
            </div>
            <div class="col-lg-2" style="margin-top: 8px;">
                <span class="label label-default" style="padding: 10px; font-size: 13px;">đến ngày: </span>
            </div>
            <div class="col-lg-4">
                <input class="form-control" type="date" id="dateEditPromotionTo">
            </div>
        </div>
        <div class="row" style="margin: 10px;">
            <div class="input-group">
                <input type="radio" id="radioEditBoutApplyPromotion" onclick="$('#divEditBoutApplyPromotion').show(); $('#radioEditDayApplyPromotion').prop('checked', false); $('#divEditDayApplyPromotion').hide();">
                <label> &nbsp Áp dụng theo lượt mua</label>
            </div><!-- /input-group -->
        </div>
        <div class="row" id="divEditBoutApplyPromotion" style="display: none">
            <div class="col-lg-5" style="margin-top: 8px; margin-bottom: 10px;">
                <span class="label label-default" style="padding: 10px; font-size: 13px;">Khuyến mãi sẽ ngừng hoạt động sau: </span>
            </div>
            <div class="col-lg-4" style="padding-left: 50px;">
                <input class="form-control" type="number" value="1" min="1" id="numberEditPromotionAfter" onkeypress='validate(event);'>
            </div>
            <div class="col-lg-3" style="margin-top: 8px; margin-bottom: 10px;">
                <span class="label label-default" style="padding: 10px; font-size: 13px;">lượt mua. </span>
            </div>
        </div>
        <div class="row" style="margin: 10px;">
            <div class="input-group">
                <input type="checkbox" id="chEditPromotionOtherPrograms">
                <label>&nbsp Không áp dụng chương trình khuyến mãi này với các chương trình khác</label>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin: 10px;">
<div class="col-lg-1"><span style="color: red">* </span></div>
<div class="col-lg-3">Kiểu khuyến mãi:</div>
<div class="col-lg-8">
<div class="row">
    <input type="hidden" id="hiddenEditPromotionStyle">
    <span><b>Khuyến mãi theo đơn hàng:</b></span>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditOrderPromotion1" onclick="setEditInfo(this.id, 1, 0); $('#hiddenEditPromotionStyle').val('1');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/1.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditOrderPromotion11">
        <span>Miễn phí vận chuyển cho đơn hàng mua trên<b>&nbsp X </b> sản phẩm.</span>
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px; display: none" id="divEditOrderPromotion12">
        <div class="row">
            <div class="col-lg-6">
                <span>Miễn phí vận chuyển cho đơn hàng mua trên<span>
            </div>
            <div class="col-lg-3">
                <input type="number" min="1" value="1" id="txtEditOrderPromotionFreeDeliveryProduct" class="form-control" onkeypress="validate(event)">
            </div>
            <div class="col-lg-3">
                <span>sản phẩm.</span>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditOrderPromotion2" onclick="setEditInfo(this.id, 2, 0); $('#hiddenEditPromotionStyle').val('2');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/2.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditOrderPromotion21">
        <span>Miễn phí vận chuyển cho đơn hàng có giá trị trên<b>&nbsp X </b> VNĐ.</span>
    </div>
    <div class="col-lg-9" style="padding: 15px; padding-left: 40px; display: none" id="divEditOrderPromotion22">
        <div class="row">
            <div class="col-lg-8">
                <span>Miễn phí vận chuyển cho đơn hàng có giá trị trên <span>
            </div>
            <div class="col-lg-3">
                <input type="text" id="txtEditOrderPromotionFreeDeliveryMoney" onkeypress="validate(event)" class="form-control">
            </div>
            <div class="col-lg-1">
                <span> VNĐ.</span>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditOrderPromotion3" onclick="setEditInfo(this.id, 3, 0); $('#hiddenEditPromotionStyle').val('3');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/3.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditOrderPromotion31">
        <span>Giảm giá cho đơn hàng có giá trị trên <b>&nbspX</b> VNĐ.</span>
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px; display: none" id="divEditOrderPromotion32">
        <div class="row">
            <div class="col-lg-1">
                <span>Giảm</span>
            </div>
            <div class="col-lg-5">
                <div class="row">
                    <div class="col-lg-6">
                        <input type="text" onkeypress="validate(event)" class="form-control" id="txtEditOrderPromotionSaleOff">
                    </div>
                    <div class="col-lg-6">
                        <select class="form-control" id="slEditOrderPromotion3">
                            <option value="0">VNĐ</option>
                            <option value="1">%</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-lg-2">
                <span>cho đơn hàng có giá trị trên </span>
            </div>
            <div class="col-lg-3">
                <input type="text" class="form-control" onkeypress="validate(event)" id="txtEditOrderPromotionMoney">
            </div>
            <div class="col-lg-1">
                <span>VNĐ</span>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditOrderPromotion4" onclick="setEditInfo(this.id, 4, 0); $('#hiddenEditPromotionStyle').val('4');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/4.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditOrderPromotion41">
        <span>Tặng quà cho đơn hàng có giá trị trên<b>&nbsp X </b> VND.</span>
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px; display: none" id="divEditOrderPromotion42">
        <div class="row">
            <div class="col-lg-6">
                <span>Tặng <span id="labelEditOrderPromotion4">quà</span> cho đơn hàng có giá trị trên <span>
            </div>
            <div class="col-lg-3">
                <input type="text" class="form-control" id="txtEditOrderPromotion4" onkeypress="validate(event)">
            </div>
            <div class="col-lg-1">
                <span> VNĐ.</span>
            </div>
            <div class="col-lg-2">
                <input type="hidden" id="hiddenEditOrderPromotion4">
                <a style="cursor: pointer" onclick="getCategoryNewsEdit(0, 0); lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion'); lightbox_open('lightAdminPromotionChooseGiftEdit', 'fadeAdminPromotionChooseGiftEdit');" id="aOrderPromotion4">Chọn quà tặng</a>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <span><b>Khuyến mãi theo sản phẩm:</b></span>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditProductPromotion1" onclick="setEditInfo(this.id, 1, 1); $('#hiddenEditPromotionStyle').val('5');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/5.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditProductPromotion11">
        <span>Mua<b> X </b> sản phẩm tặng <b>1</b> sản phẩm cùng loại.</span>
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px; display: none" id="divEditProductPromotion12">
        <div class="row">
            <div class="col-lg-1">
                <span>Mua <span>
            </div>
            <div class="col-lg-3">
                <input type="number" id="txtEditProductPromotionFree1Product" onkeypress="validate(event)" class="form-control" min="1" value="1">
            </div>
            <div class="col-lg-5">
                </span> sản phẩm tặng <b>1</b> sản phẩm cùng loại.</span>
            </div>
            <div class="col-lg-3">
                <input type="hidden" id="hiddenEditProductPromotion1">
                <a style="cursor: pointer" id="aEditProductPromotion1" onclick="getCategoryNewsEdit(1, 0); lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion'); lightbox_open('lightAdminPromotionBuyXGet1Edit', 'fadeAdminPromotionBuyXGet1Edit');">Chọn sản phẩm áp dụng.</a>
            </div>
        </div>
        <div class="row" style="margin-top: 10px;">
            <p style="text-decoration: underline">Các sản phẩm hiện đang được áp dụng: </p>
            <ul id="ulProductPromotion1"></ul>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditProductPromotion2" onclick="setEditInfo(this.id, 2, 1); $('#hiddenEditPromotionStyle').val('6');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/6.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditProductPromotion21">
        <span>Mua<b> X </b> sản phẩm tặng <b>Y</b> sản phẩm khác.</span>
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px; display: none" id="divEditProductPromotion22">
        <div class="row">
            <div class="col-lg-1">
                <span>Mua <span>
            </div>
            <div class="col-lg-2">
                <input type="number" id="txtEditProductPromotionFreeXProduct" onkeypress="validate(event)" class="form-control" min="1" value="1">
            </div>
            <div class="col-lg-2">
                <span id="spanEditProductPromotion21"> sản phẩm tặng </span>
            </div>
            <div class="col-lg-2">
                <input type="number" id="txtEditProductPromotionFreeYProduct" onkeypress="validate(event)" class="form-control" min="1" value="1">
            </div>
            <div class="col-lg-3">
                <span id="spanEditProductPromotion22"> sản phẩm khác. </span>
            </div>
            <div class="col-lg-2">
                <input type="hidden" id="hiddenEditProductPromotion2">
                <a style="cursor: pointer" id="aEditProductPromotion2" onclick="getCategoryNewsEdit(2, 0); getCategoryNewsEdit(3, 0); lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion'); lightbox_open('lightAdminPromotionBuyXGetYEdit', 'fadeAdminPromotionBuyXGetYEdit');">Chọn sản phẩm áp dụng.</a>
            </div>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditProductPromotion3" onclick="setEditInfo(this.id, 3, 1); $('#hiddenEditPromotionStyle').val('7');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/7.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditProductPromotion31">
        <span>Giảm giá sản phẩm khi mua số lượng lớn.</span>
    </div>
    <div class="col-lg-10" style="padding: 5px; padding-left: 40px; display: none" id="divEditProductPromotion32">
        <div class="row">
            <div class="col-lg-1">
                <span>Mua <span>
            </div>
            <div class="col-lg-2">
                <input type="number" id="txtEditProductPromotionAmount" onkeypress="validate(event)" class="form-control" min="1" value="1">
            </div>
            <div class="col-lg-3">
                </span> sản phẩm được giảm giá </span>
            </div>
            <div class="col-lg-3">
                <input type="text" id="txtEditProductPromotionDiscount" onkeypress="validate(event)" class="form-control">
            </div>
            <div class="col-lg-3">
                <select class="form-control" id="slEditProductPromotion3">
                    <option value="0">VNĐ</option>
                    <option value="1">%</option>
                </select>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4">
                <span> trên mỗi sản phẩm. </span>
            </div>
            <div class="col-lg-8">
                <input type="hidden" id="hiddenEditProductPromotion3">
                <a style="cursor: pointer" id="aEditProductPromotion3" onclick="getCategoryNewsEdit(4, 0); lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion'); lightbox_open('lightAdminPromotionBuyBigXGetYEdit', 'fadeAdminPromotionBuyBigXGetYEdit');">Chọn sản phẩm áp dụng.</a>
            </div>
        </div>
        <div class="row" style="margin-top: 10px;">
            <p style="text-decoration: underline">Các sản phẩm hiện đang được áp dụng: </p>
            <ul id="ulProductPromotion3"></ul>
        </div>
    </div>
</div>
<div class="row" style="margin: 5px;">
    <div class="col-lg-1" style="padding: 15px;">
        <input type="radio" id="radioEditProductPromotion4" onclick="setEditInfo(this.id, 4, 1); $('#hiddenEditPromotionStyle').val('8');">
    </div>
    <div class="col-lg-1">
        <img src="<?php echo base_url() ?>assets/images/promotion/8.png">
    </div>
    <div class="col-lg-10" style="padding: 15px; padding-left: 40px;" id="divEditProductPromotion41">
        <span>Giảm giá cho tất cả các sản phẩm thuộc danh mục.</span>
    </div>
    <div class="col-lg-10" style="padding: 5px; padding-left: 40px; display: none" id="divEditProductPromotion42">
        <div class="row">
            <div class="col-lg-1">
                <span>Giảm <span>
            </div>
            <div class="col-lg-3">
                <input type="text" id="txtEditProductPromotionDiscountAll" onkeypress="validate(event)" class="form-control">
            </div>
            <div class="col-lg-3">
                <select class="form-control" id="slEditProductPromotion4">
                    <option value="0">VNĐ</option>
                    <option value="1">%</option>
                </select>
            </div>
            <div class="col-lg-3">
                <span> cho tất cả các sản phẩm thuộc danh mục <span id="spanEditProductPromotion4"></span>. </span>
            </div>
            <div class="col-lg-2">
                <input type="hidden" id="hiddenEditProductPromotion4">
                <a style="cursor: pointer" id="aEditProductPromotion4" onclick="getCategoryNewsEdit(5, 0); lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion'); lightbox_open('lightAdminPromotionBuyAnyGetYEdit', 'fadeAdminPromotionBuyAnyGetYEdit');">Chọn danh mục sản phẩm áp dụng.</a>
            </div>
        </div>
    </div>
</div>
</div>
</div>
<div class="row" style="margin: 10px;">
    <div class="col-lg-1"></div>
    <div class="col-lg-3">Thông báo hiển thị:</div>
    <div class="col-lg-8">
        <textarea id="txtEditPromotionInform" class="form-control"></textarea>
    </div>
</div>
<div class="row" style="margin: 10px;">
    <div class="col-md-12">
        <div class="row" style="margin: 20px; text-align: center;">
            <input type="hidden" id="hiddenEditAdminPromotionID">
            <span class="btn btn-success" style="margin: 5px" id="spnEditAdv" onclick="editNewAdminPromotion();">Cập nhật</span>
            <span class="btn btn-success" style="margin: 5px" id="spnEditAdv" onclick="lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
        </div>
    </div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid fade" id="fadeEditAdminPromotion" onClick="lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Edit Control Panel -->

<!---------------------------------------- CHOOSE GIFT (MENU 0) ---------------------------------------- !>
<!-- input Control Panel -->
<div class="row light" id="lightAdminPromotionChooseGiftEdit" style="width: 50%; height: inherit; top: 15%; left: 35%; border: 1px solid #000">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><b>CHỌN QUÀ TẶNG</b></h3>
        </div>
        <div class="panel-body">
            <div class="row" style="padding: 5px;"><span>Chọn quà tặng cho đơn hàng có giá trị trên <b>&nbspX</b> vnđ</span></div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                </div>
                <div class="col-lg-9" id="divCategoryEditPromotionMenu0" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
            </div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn sản phẩm </label>
                </div>
                <div class="col-lg-9">
                    <select class="form-control" id="slProductEditPromotion" size="10" style="width: 100%; padding: 10px;"></select>
                </div>
            </div>
            <div class="row" style="padding: 10px;">
                <div class="col-lg-1">
                    <input type="hidden" id="hiddenChooseGiftEdit" value="0">
                    <input type="checkbox" id="chChooseGiftEdit" onclick="if($('#hiddenChooseGiftEdit').val() == '0'){$('#txtChooseGiftEdit').attr('disabled', false); $('#hiddenChooseGiftEdit').val('1')} else{$('#txtChooseGiftEdit').attr('disabled', true); $('#hiddenChooseGiftEdit').val('0')}">
                </div>
                <div class="col-lg-4">
                    <span>Quà tặng không phải sản phẩm</span>
                </div>
                <div class="col-lg-7">
                    <input class="form-control" type="text" id="txtChooseGiftEdit" disabled>
                </div>
            </div>
            <div class="row" style="text-align: center; padding: 5px;">
                <span class="btn btn-success" onclick="chooseGiftEdit()">Chọn</span>
                <span class="btn btn-success" onclick="lightbox_close('lightAdminPromotionChooseGiftEdit', 'fadeAdminPromotionChooseGiftEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
            </div>
        </div>
    </div>
</div>
<div class="fade" id="fadeAdminPromotionChooseGiftEdit" onClick="lightbox_close('lightAdminPromotionChooseGiftEdit', 'fadeAdminPromotionChooseGiftEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Control Panel -->

<!---------------------------------------- BUY X GET 1 (MENU 1) ---------------------------------------- !>
<!-- input Control Panel -->
<div class="row light" id="lightAdminPromotionBuyXGet1Edit" style="width: 50%; height: inherit; top: 15%; left: 35%; border: 1px solid #000">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><b>CHỌN SẢN PHẨM ÁP DỤNG CHƯƠNG TRÌNH KHUYẾN MÃI</b></h3>
        </div>
        <div class="panel-body">
            <div class="row" style="padding: 5px;"><span>Mua <b>&nbspX</b> sản phẩm tặng <b>&nbspY</b> sản phẩm cùng loại.</span></div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                </div>
                <div class="col-lg-9" id="divCategoryEditPromotionMenu1" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
            </div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn sản phẩm </label>
                </div>
                <div class="col-lg-9">
                    <select class="form-control" id="slProductEditPromotionMenu1" size="10" style="width: 100%; padding: 10px;" multiple></select>
                </div>
            </div>
            <div class="row" style="text-align: center; padding: 5px;">
                <span class="btn btn-success" onclick="chooseProductBuyXGet1Edit()">Chọn</span>
                <span class="btn btn-success" onclick="lightbox_close('lightAdminPromotionBuyXGet1Edit', 'fadeAdminPromotionBuyXGet1Edit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
            </div>
        </div>
    </div>
</div>
<div class="fade" id="fadeAdminPromotionBuyXGet1Edit" onClick="lightbox_close('lightAdminPromotionBuyXGet1Edit', 'fadeAdminPromotionBuyXGet1Edit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Control Panel -->

<!---------------------------------------- BUY X GET Y (MENU 2) ---------------------------------------- !>
<!-- input Control Panel -->
<div class="row light" id="lightAdminPromotionBuyXGetYEdit" style="width: 80%; height: inherit; top: 15%; left: 20%; border: 1px solid #000">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><b>CHỌN SẢN PHẨM ÁP DỤNG CHƯƠNG TRÌNH KHUYẾN MÃI</b></h3>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-6" style="padding-right: 20px;">
                    <div class="row">
                        <label style="text-decoration: underline; padding: 5px;">Chọn sản phẩm mua</label>
                    </div>
                    <div class="row">
                        <div class="col-lg-3" style="padding: 5px;">
                            <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                        </div>
                        <div class="col-lg-9" id="divCategoryEditPromotionMenu21" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3" style="padding: 5px;">
                            <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn sản phẩm </label>
                        </div>
                        <div class="col-lg-9">
                            <select class="form-control" id="slProductEditPromotionMenu21" size="10" style="width: 100%; padding: 10px;"></select>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6">
                    <div class="row">
                        <label style="text-decoration: underline; padding: 5px;">Chọn sản phẩm tặng</label>
                    </div>
                    <div class="row">
                        <div class="col-lg-3" style="padding: 5px;">
                            <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                        </div>
                        <div class="col-lg-9" id="divCategoryEditPromotionMenu22" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3" style="padding: 5px;">
                            <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn sản phẩm </label>
                        </div>
                        <div class="col-lg-9">
                            <select class="form-control" id="slProductEditPromotionMenu22" size="10" style="width: 100%; padding: 10px;"></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" style="text-align: center; padding: 5px;">
                <span class="btn btn-success" onclick="chooseProductBuyXGetYEdit()">Chọn</span>
                <span class="btn btn-success" onclick="lightbox_close('lightAdminPromotionBuyXGetYEdit', 'fadeAdminPromotionBuyXGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
            </div>
        </div>
    </div>
</div>
<div class="fade" id="fadeAdminPromotionBuyXGetYEdit" onClick="lightbox_close('lightAdminPromotionBuyXGetYEdit', 'fadeAdminPromotionBuyXGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Control Panel -->

<!---------------------------------------- BUY BIG X GET Y (MENU 3) ---------------------------------------- !>
<!-- input Control Panel -->
<div class="row light" id="lightAdminPromotionBuyBigXGetYEdit" style="width: 50%; height: inherit; top: 15%; left: 35%; border: 1px solid #000">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><b>CHỌN SẢN PHẨM ÁP DỤNG CHƯƠNG TRÌNH KHUYẾN MÃI</b></h3>
        </div>
        <div class="panel-body">
            <div class="row" style="padding: 5px;"><span>Giảm giá sản phẩm khi mua số lượng lớn.</span></div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                </div>
                <div class="col-lg-9" id="divCategoryEditPromotionMenu3" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
            </div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn sản phẩm </label>
                </div>
                <div class="col-lg-9">
                    <select class="form-control" id="slProductEditPromotionMenu3" size="10" style="width: 100%; padding: 10px;" multiple></select>
                </div>
            </div>
            <div class="row" style="text-align: center; padding: 5px;">
                <span class="btn btn-success" onclick="chooseProductBuyBigXGetYEdit()">Chọn</span>
                <span class="btn btn-success" onclick="lightbox_close('lightAdminPromotionBuyBigXGetYEdit', 'fadeAdminPromotionBuyBigXGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
            </div>
        </div>
    </div>
</div>
<div class="fade" id="fadeAdminPromotionBuyBigXGetYEdit" onClick="lightbox_close('lightAdminPromotionBuyBigXGetYEdit', 'fadeAdminPromotionBuyBigXGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Control Panel -->

<!---------------------------------------- BUY ANY GET Y (MENU 4) ---------------------------------------- !>
<!-- input Control Panel -->
<div class="row light" id="lightAdminPromotionBuyAnyGetYEdit" style="width: 50%; height: inherit; top: 15%; left: 35%; border: 1px solid #000">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><b>CHỌN DANH MỤC SẢN PHẨM ÁP DỤNG CHƯƠNG TRÌNH KHUYẾN MÃI</b></h3>
        </div>
        <div class="panel-body">
            <div class="row" style="padding: 5px;"><span>Giảm giá cho tất cả các sản phẩm thuộc danh mục</span></div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-default" style="padding: 10px; font-size: 14px;">Chọn danh mục</label>
                </div>
                <div class="col-lg-9" id="divCategoryEditPromotionMenu4" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px;"></div>
            </div>
            <div class="row">
                <div class="col-lg-3" style="padding: 5px;">
                    <label class="label label-primary" style="padding: 10px; font-size: 14px;">Danh mục đã chọn</label>
                </div>
                <div class="col-lg-9" id="divChosenCategoryEditPromotionMenu4" style="height: 130px; overflow: auto; padding-top: 5px; margin-bottom: 5px; font-weight: bold"></div>
            </div>
            <div class="row" style="text-align: center; padding: 5px;">
                <span class="btn btn-success" onclick="chooseProductBuyAnyGetYEdit()">Chọn</span>
                <span class="btn btn-success" onclick="lightbox_close('lightAdminPromotionBuyAnyGetYEdit', 'fadeAdminPromotionBuyAnyGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');">Đóng cửa sổ</span>
            </div>
        </div>
    </div>
</div>
<div class="fade" id="fadeAdminPromotionBuyAnyGetYEdit" onClick="lightbox_close('lightAdminPromotionBuyAnyGetYEdit', 'fadeAdminPromotionBuyAnyGetYEdit'); lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');"></div>
<!-- end input Control Panel -->

<script>
    function setValueUpdateEditAdminPromotion(promotionID, promotionName, promotionStatus, promotionFrom, promotionTo, buyingBouts, otherPrograms, buyingValue, gettingValue, detailStyle, productApply, promotionStyle, promotionInform){
        $('#hiddenEditAdminPromotionID').val(promotionID);
        $('#txtEditPromotionName').val(promotionName);
        if(promotionStatus == 0){
            $('#slEditPromotionStatus').val('0');
        }
        else{
            $('#slEditPromotionStatus').val('1');
        }

        if(buyingBouts == 0){
            $('#dateEditPromotionFrom').val(promotionFrom);
            $('#dateEditPromotionTo').val(promotionTo);
            $('#radioEditDayApplyPromotion').click();
        }
        else{
            $('#numberEditPromotionAfter').val(buyingBouts);
            $('#radioEditBoutApplyPromotion').click();
        }

        if(otherPrograms == 1){
            $('#chEditPromotionOtherPrograms').prop("checked", true);
        }
        else{
            $('#chEditPromotionOtherPrograms').prop("checked", false);
        }

        $('#txtEditPromotionInform').val(promotionInform);

        $('#hiddenEditPromotionStyle').val(promotionStyle);
        if(['1','2','3','4'].indexOf(promotionStyle) > -1){  //kiem tra ton tai trong 1 mang dung javascript
            if(promotionStyle == 1){
                $('#txtEditOrderPromotionFreeDeliveryProduct').val(buyingValue);
            }
            if(promotionStyle == 2){
                $('#txtEditOrderPromotionFreeDeliveryMoney').val(buyingValue);
            }
            if(promotionStyle == 3){
                $('#txtEditOrderPromotionMoney').val(buyingValue);
                $('#txtEditOrderPromotionSaleOff').val(gettingValue);
                if(detailStyle == 0){
                    $('#slEditOrderPromotion3').val('0');
                }
                else{
                    $('#slEditOrderPromotion3').val('1');
                }
            }
            if(promotionStyle == 4){
                var name = getNameProductByID(gettingValue);
                $('#labelEditOrderPromotion4').html("<b>"+name+"</b>");
                $('#hiddenEditOrderPromotion4').val(gettingValue);
                $('#txtEditOrderPromotion4').val(buyingValue);
            }
            $("#radioEditOrderPromotion"+promotionStyle).click();
        }
        else{
            if(promotionStyle == 5){
                $('#txtEditProductPromotionFree1Product').val(buyingValue);
                var string = "";
                var myArr = productApply.split(",");
                for(var i = 0; i < myArr.length; i++){
                    var name = getNameProductByID(myArr[i]);
                    $("#ulProductPromotion1").append("<li><b>"+name+"</b></li>");
                    string += name+",";
                }
                var stringAfter = string.substr(0, string.length-1);
                $('#hiddenEditProductPromotion1').val(stringAfter);
            }

            if(promotionStyle == 6){
                $('#txtEditProductPromotionFreeXProduct').val(buyingValue);
                $('#txtEditProductPromotionFreeYProduct').val(gettingValue);
                var myArr = productApply.split(",");
                var string = getNameProductByID(myArr[0])+","+getNameProductByID(myArr[1]);
                $('#hiddenEditProductPromotion2').val(string);
                $('#spanEditProductPromotion21').html("<b>"+getNameProductByID(myArr[0])+"</b>"+" tặng");
                $('#spanEditProductPromotion22').html("<b>"+getNameProductByID(myArr[1])+"</b>");
            }

            if(promotionStyle == 7){
                $('#txtEditProductPromotionAmount').val(buyingValue);
                $('#txtEditProductPromotionDiscount').val(gettingValue);
                if(detailStyle == 0){
                    $('#slEditProductPromotion3').val('0');
                }
                else{
                    $('#slEditProductPromotion3').val('1');
                }
                var string = "";
                var myArr = productApply.split(",");
                for(var i = 0; i < myArr.length; i++){
                    var name = getNameProductByID(myArr[i]);
                    $("#ulProductPromotion3").append("<li><b>"+name+"</b></li>");
                    string += name+",";
                }
                var stringAfter = string.substr(0, string.length-1);
                $('#hiddenEditProductPromotion3').val(stringAfter);
            }

            if(promotionStyle == 8){
                $('#txtEditProductPromotionDiscountAll').val(gettingValue);
                if(detailStyle == 0){
                    $('#slEditProductPromotion4').val('0');
                }
                else{
                    $('#slEditProductPromotion4').val('1');
                }
                $('#hiddenEditProductPromotion4').val(productApply);
                $('#spanEditProductPromotion4').html("<b>"+getNameProductByID(productApply, 1)+"</b>");
            }

            $("#radioEditProductPromotion"+(promotionStyle-4)).click();
        }

        lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
    }

    function chooseGiftEdit(){
        if($('#slProductEditPromotion > option').length == 0 && !$('#chChooseGiftEdit').is(":checked")){
            alert("Bạn chưa chọn quà tặng!");
        }
        else{
            if($('#chChooseGiftEdit').is(":checked")){
                var product = $('#txtChooseGiftEdit').val();
                if(product == ""){
                    alert("Xin vui lòng nhập tên quà tặng...");
                }
                else{
                    $('#hiddenEditOrderPromotion4').val(product);
                    $('#labelEditOrderPromotion4').html("<b>"+product+"</b>");
                    lightbox_close('lightAdminPromotionChooseGiftEdit', 'fadeAdminPromotionChooseGiftEdit');
                    lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
                }
            }
            else{
                var product = $('#slProductEditPromotion').val();
                if(product == null){
                    alert("Xin vui lòng chọn một sản phẩm bất kỳ...");
                }
                else{
                    $('#hiddenEditOrderPromotion4').val(product);
                    $('#labelEditOrderPromotion4').html("<b>"+product+"</b>");
                    lightbox_close('lightAdminPromotionChooseGiftEdit', 'fadeAdminPromotionChooseGiftEdit');
                    lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
                }
            }
        }
    }

    function chooseProductBuyXGet1Edit(){
        var data = $('#slProductEditPromotionMenu1').val();
        if(data == null){
            alert("Xin vui lòng chọn ít nhất một sản phẩm...");
        }
        else{
            $('#hiddenEditProductPromotion1').val(data);
            $("#ulProductPromotion1").html("");
            var myArr = data.toString().split(",");
            for(var i = 0; i < myArr.length; i++){
                $("#ulProductPromotion1").append("<li><b>"+myArr[i]+"</b></li>");
            }
            lightbox_close('lightAdminPromotionBuyXGet1Edit', 'fadeAdminPromotionBuyXGet1Edit');
            lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
        }
    }

    function chooseProductBuyXGetYEdit(){
        var data1 = $('#slProductEditPromotionMenu21').val();
        var data2 = $('#slProductEditPromotionMenu22').val();

        if(data1 == null || data2 == null){
            alert("Xin vui lòng chọn một sản phẩm...");
        }
        else{
            $('#hiddenEditProductPromotion2').val(data1+","+data2);
            $('#spanEditProductPromotion21').html("<b>"+data1+"</b>"+" tặng");
            $('#spanEditProductPromotion22').html("<b>"+data2+"</b>");
            lightbox_close('lightAdminPromotionBuyXGetYEdit', 'fadeAdminPromotionBuyXGetYEdit');
            lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
        }
    }

    function chooseProductBuyBigXGetYEdit(){
        var data = $('#slProductEditPromotionMenu3').val();

        if(data == null){
            alert("Xin vui lòng chọn ít nhất một sản phẩm...");
        }
        else{
            $('#hiddenEditProductPromotion3').val(data);
            $("#ulProductPromotion3").html("");
            var myArr = data.toString().split(",");
            for(var i = 0; i < myArr.length; i++){
                $("#ulProductPromotion3").append("<li><b>"+myArr[i]+"</b></li>");
            }
            lightbox_close('lightAdminPromotionBuyBigXGetYEdit', 'fadeAdminPromotionBuyBigXGetYEdit');
            lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
        }
    }

    function chooseProductBuyAnyGetYEdit(){
        var data = $('#hiddenEditProductPromotion4').val();
        if(data == ""){
            alert("Xin vui lòng chọn một danh mục bất kỳ...");
        }
        else{
            if(data == 0){
                $('#spanEditProductPromotion4').html("<b>Tất cả danh mục</b>");
                lightbox_close('lightAdminPromotionBuyAnyGetYEdit', 'fadeAdminPromotionBuyAnyGetYEdit');
                lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
            }
            else{
                var cate = $('#divChosenCategoryEditPromotionMenu4').html();
                var myArr = cate.split(" &gt; ");
                var cateAfter = myArr[myArr.length-2];
                $('#spanEditProductPromotion4').html("<b>"+cateAfter+"</b>");
                lightbox_close('lightAdminPromotionBuyAnyGetYEdit', 'fadeAdminPromotionBuyAnyGetYEdit');
                lightbox_open('lightEditAdminPromotion', 'fadeEditAdminPromotion');
            }
        }
    }

    function editNewAdminPromotion(){
        var id = $('#hiddenEditAdminPromotionID').val();
        var promotionName = $('#txtEditPromotionName').val();
        var promotionStatus = $('#slEditPromotionStatus').val();
        var promotionFrom = $('#dateEditPromotionFrom').val();
        var promotionTo = $('#dateEditPromotionTo').val();
        var buying_bouts = $('#numberEditPromotionAfter').val();

        var other_programs = 0;
        if($('#chEditPromotionOtherPrograms').is(":checked")){
            other_programs = 1;
        }

        var promotionInform = $('#txtEditPromotionInform').val();

        if(promotionName == ''){
            alert("Xin vui lòng nhập tên khuyến mãi...");
        }
        else if($('#radioEditDayApplyPromotion').is(":checked")){
            if(promotionFrom == '' || promotionTo == ''){
                alert("Xin vui lòng chọn ngày bắt đầu và ngày kết thúc đặt hạn áp dụng khuyến mãi...");
            }
            else if(promotionFrom > promotionTo){
                alert("Ngày bắt đầu hạn áp dụng khuyến mãi phải nhỏ hơn hoặc bằng ngày kết thúc!");
            }
            else{
                var dataString = "id="+id+"&promotionName="+promotionName+"&promotionStatus="+promotionStatus+"&promotionFrom="+promotionFrom+"&promotionTo="+promotionTo+"&buying_bouts="+null+"&other_programs="+other_programs+"&promotionInform="+promotionInform;
                checkPromotionStyleEdit(dataString);
            }
        }
        else if($('#radioEditBoutApplyPromotion').is(":checked")){
            if(buying_bouts < 1){
                alert("Số lượt mua phải lớn hơn hoặc bằng 1!");
            }
            else{
                var dataString = "id="+id+"&promotionName="+promotionName+"&promotionStatus="+promotionStatus+"&promotionFrom="+null+"&promotionTo="+null+"&buying_bouts="+buying_bouts+"&other_programs="+other_programs+"&promotionInform="+promotionInform;
                checkPromotionStyleEdit(dataString);
            }
        }
    }

    function checkPromotionStyleEdit(info){
        var info = info;
        var promotion_style = $('#hiddenEditPromotionStyle').val();
        var getting_value = null;
        var buying_value = null;
        var detail_style = null;

        if(promotion_style == '1'){
            buying_value = parseFloat($('#txtEditOrderPromotionFreeDeliveryProduct').val());
            detail_style = 2;
            if(buying_value < 1 || $('#txtEditOrderPromotionFreeDeliveryProduct').val() == ''){
                alert("Số lượng sản phẩm mua hàng phải lớn hơn hoặc bằng 1!");
            }
            else{
                var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style;
                updatePromotion(dataString);
            }
        }
        if(promotion_style == '2'){
            buying_value = parseFloat($('#txtEditOrderPromotionFreeDeliveryMoney').val());
            detail_style = 0;
            if(buying_value < 1 || $('#txtEditOrderPromotionFreeDeliveryMoney').val() == ''){
                alert("Tổng giá trị đơn hàng phải lớn hơn hoặc bằng 1!");
            }
            else{
                var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style;
                updatePromotion(dataString);
            }
        }
        if(promotion_style == '3'){
            buying_value = parseFloat($('#txtEditOrderPromotionMoney').val());
            getting_value = parseFloat($('#txtEditOrderPromotionSaleOff').val());
            detail_style = $('#slEditOrderPromotion3').val();
            if(detail_style == '0'){
                if(buying_value < 1 || getting_value < 1 || $('#txtEditOrderPromotionMoney').val() == '' || $('#txtEditOrderPromotionSaleOff').val() == ''){
                    alert("Tổng số tiền chiết khấu và tổng giá trị đơn hàng phải lớn hơn hoặc bằng 1!");
                }
                else if(buying_value < getting_value){
                    alert("Tổng số tiền chiết khấu phải nhỏ hơn hoặc bằng tổng giá trị đơn hàng!");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style;
                    updatePromotion(dataString);
                }
            }
            else{
                if(buying_value < 1 || getting_value == 0 || getting_value > 100 || $('#txtEditOrderPromotionMoney').val() == '' || $('#txtEditOrderPromotionSaleOff').val() == ''){
                    alert("Tổng số tiền chiết khấu phải lớn hơn 0%, nhỏ hơn hoặc bằng 100% và tổng giá trị đơn hàng phải lớn hơn hoặc bằng 1!");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style;
                    updatePromotion(dataString);
                }
            }
        }
        if(promotion_style == '4'){
            buying_value = parseFloat($('#txtEditOrderPromotion4').val());
            getting_value = $('#hiddenEditOrderPromotion4').val();
            detail_style = 0;
            if(buying_value < 1 || $('#txtEditOrderPromotion4').val() == ''){
                alert("Tổng giá trị đơn hàng phải lớn hơn hoặc bằng 1!");
            }
            else{
                if(getting_value == ''){
                    alert("Xin vui lòng chọn quà tặng!");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style;
                    updatePromotion(dataString);
                }
            }
        }
        if(promotion_style == '5'){
            buying_value = parseFloat($('#txtEditProductPromotionFree1Product').val());
            getting_value = 1;
            detail_style = 2;
            var value = $('#hiddenEditProductPromotion1').val();
            if(buying_value < 1 || $('#txtEditProductPromotionFree1Product').val() == ''){
                alert("Số lượng sản phẩm mua hàng phải lớn hơn hoặc bằng 1!");
            }
            else if(value == ''){
                alert("Xin vui lòng chọn sản phẩm áp dụng...");
            }
            else{
                var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                updatePromotion(dataString);
            }
        }
        if(promotion_style == '6'){
            buying_value = parseFloat($('#txtEditProductPromotionFreeXProduct').val());
            getting_value = parseFloat($('#txtEditProductPromotionFreeYProduct').val());
            detail_style = 2;
            var value = $('#hiddenEditProductPromotion2').val();
            if(buying_value < 1 || getting_value < 1 || $('#txtEditProductPromotionFreeXProduct').val() == '' || $('#txtEditProductPromotionFreeYProduct').val() == ''){
                alert("Số lượng sản phẩm mua (tặng) phải lớn hơn hoặc bằng 1!");
            }
            else if(value == ''){
                alert("Xin vui lòng chọn sản phẩm áp dụng...");
            }
            else{
                var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                updatePromotion(dataString);
            }
        }
        if(promotion_style == '7'){
            buying_value = parseFloat($('#txtEditProductPromotionAmount').val());
            getting_value = parseFloat($('#txtEditProductPromotionDiscount').val());
            detail_style = $('#slEditProductPromotion3').val();
            var value = $('#hiddenEditProductPromotion3').val();
            if(detail_style == '0'){
                if(buying_value < 1 || getting_value < 1 || $('#txtEditProductPromotionAmount').val() == '' || $('#txtEditProductPromotionDiscount').val() == ''){
                    alert("Số lượng sản phẩm mua hàng và tổng số tiền chiết khấu phải lớn hơn hoặc bằng 1!");
                }
                else if(value == ''){
                    alert("Xin vui lòng chọn sản phẩm áp dụng...");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                    updatePromotion(dataString);
                }
            }
            else{
                if(buying_value < 1 || getting_value == 0 || getting_value > 100 || $('#txtEditProductPromotionAmount').val() == '' || $('#txtEditProductPromotionDiscount').val() == ''){
                    alert("Số lượng sản phẩm mua phải lớn hơn hoặc bằng 1 và tổng số tiền chiết khấu phải lớn hơn 0%, nhỏ hơn hoặc bằng 100%!");
                }
                else if(value == ''){
                    alert("Xin vui lòng chọn sản phẩm áp dụng...");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                    updatePromotion(dataString);
                }
            }
        }
        if(promotion_style == '8'){
            getting_value = parseFloat($('#txtEditProductPromotionDiscountAll').val());
            detail_style = $('#slEditProductPromotion4').val();
            var value = $('#hiddenEditProductPromotion4').val();
            if(detail_style == '0'){
                if(getting_value < 1 || $('#txtEditProductPromotionDiscountAll').val() == ''){
                    alert("Tổng số tiền chiết khấu phải lớn hơn hoặc bằng 1!");
                }
                else if(value == ''){
                    alert("Xin vui lòng chọn danh mục sản phẩm áp dụng...");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                    updatePromotion(dataString);
                }
            }
            else{
                if(getting_value == 0 || getting_value > 100 || $('#txtEditProductPromotionDiscountAll').val() == ''){
                    alert("Tổng số tiền chiết khấu phải lớn hơn 0%, nhỏ hơn hoặc bằng 100%!");
                }
                else if(value == ''){
                    alert("Xin vui lòng chọn danh mục sản phẩm áp dụng...");
                }
                else{
                    var dataString = info+"&buying_value="+buying_value+"&getting_value="+getting_value+"&detail_style="+detail_style+"&promotion_style="+promotion_style+"&value="+value;
                    updatePromotion(dataString);
                }
            }
        }
    }

    function updatePromotion(dataString){
        var dataString = dataString;
        var url = "<?php echo base_url(); ?>";
        $.ajax({
            type: "POST",
            url: url+"admin_promotion/updatePromotion",
            data: dataString,
            success: function(x){
//                alert(x);
                if(x != 0){
                    alert("Đã xảy ra lỗi. Xin vui lòng tải lại trình duyệt và thử lại...");
                }
                else{
                    alert("Cập nhật thành công!");
                    lightbox_close('lightEditAdminPromotion', 'fadeEditAdminPromotion');
                    getTablePromotionManager();
                    getPage();
                }
            }
        });
    }

    function deletePromotion(id){
        //alert(id);
        var check = confirm("Bạn chắc chắn muốn xóa?");
        if(check == true){
            var id = id;
            var url = "<?php echo base_url() ?>";
            var dataString = "id="+id;

            $.ajax({
                type: "POST",
                url: url+"admin_promotion/deletePromotion",
                data: dataString,
                success: function(x){
                    //alert(x);
                    if(x == 0){
                        getTablePromotionManager();
                        getPage();
                    }
                    else{
                        alert(x);
                    }
                }
            });
        }
        else{
            return;
        }
    }

    function getNameProductByID(id, isCate){
//        alert(id);
        var isCate = isCate;
        var id = id;
        var url = "<?php echo base_url() ?>";
        var dataString = "productID="+id;
        var name = '';
        $.ajax({
            async: false,
            type: "POST",
            url: url+"admin_promotion/getNameProductByID/"+isCate,
            data: dataString,
            success: function(x){
//                alert(x);
                name = x;
            }
        });
        return name;
    }
</script>

<script>
    function getCategoryNewsEdit(i, idCate){
        var url = "<?php echo base_url() ?>";
        $.ajax({
            url: url+"admin_promotion/getEditParentCategory/"+i+"/"+idCate,
            success: function(x){
//                alert(x);
                if(i == 0){
                    $('#divCategoryEditPromotionMenu0').html(x);
                }
                if(i == 1){
                    $('#divCategoryEditPromotionMenu1').html(x);
                }
                if(i == 2){
                    $('#divCategoryEditPromotionMenu21').html(x);
                }
                if(i == 3){
                    $('#divCategoryEditPromotionMenu22').html(x);
                }
                if(i == 4){
                    $('#divCategoryEditPromotionMenu3').html(x);
                }
                if(i == 5){
                    $('#divCategoryEditPromotionMenu4').html(x);
                }
            }
        });
    }

    function getCategoryProductEdit(i, idCate){
        var idCate = idCate;
        var url = "<?php echo base_url() ?>";
        var dataString = "idCate="+idCate;
        $.ajax({
            type: "POST",
            url: url+"admin_promotion/getAddCategoryProduct",
            data: dataString,
            success: function(x){
//                alert(x);
                if(i == 0){
                    $("#slProductEditPromotion option").remove();
                }
                if(i == 1){
                    $("#slProductEditPromotionMenu1 option").remove();
                }
                if(i == 2){
                    $("#slProductEditPromotionMenu21 option").remove();
                }
                if(i == 3){
                    $("#slProductEditPromotionMenu22 option").remove();
                }
                if(i == 4){
                    $("#slProductEditPromotionMenu3 option").remove();
                }
                var myArrResult = x.split(", ");
                for(var k = 0; k < myArrResult.length-1; k++){
                    if(i == 0){
                        $("#slProductEditPromotion").append("<option style='margin: 5px;' value='"+myArrResult[k]+"'>"+myArrResult[k]+"</option>");
                    }
                    if(i == 1){
                        $("#slProductEditPromotionMenu1").append("<option style='margin: 5px;' value='"+myArrResult[k]+"'>"+myArrResult[k]+"</option>");
                    }
                    if(i == 2){
                        $("#slProductEditPromotionMenu21").append("<option style='margin: 5px;' value='"+myArrResult[k]+"'>"+myArrResult[k]+"</option>");
                    }
                    if(i == 3){
                        $("#slProductEditPromotionMenu22").append("<option style='margin: 5px;' value='"+myArrResult[k]+"'>"+myArrResult[k]+"</option>");
                    }
                    if(i == 4){
                        $("#slProductEditPromotionMenu3").append("<option style='margin: 5px;' value='"+myArrResult[k]+"'>"+myArrResult[k]+"</option>");
                    }
                }
            }
        });
    }
</script>

<script>
    function validate(evt) {
        var theEvent = evt || window.event;
        var key = theEvent.keyCode || theEvent.which;
        key = String.fromCharCode( key );
        var regex = /[0-9]/;
        if( !regex.test(key) ) {
            theEvent.returnValue = false;
            if(theEvent.preventDefault) theEvent.preventDefault();
        }
    }
</script>

<script>
    function setEditInfo(id, k, status){
        for(var i = 1; i <= 4; i++){
            var idRadioPromotion = "radioEditOrderPromotion"+i;
            if(idRadioPromotion != id){
                $('#'+idRadioPromotion).prop("checked", false);
                displayEdit(0, i, 1);
            }

            var idRadioProduct = "radioEditProductPromotion"+i;
            if(idRadioProduct != id){
                $('#'+idRadioProduct).prop("checked", false);
                displayEdit(1, i, 1);
            }
        }

        displayEdit(status, k, 0);
    }

    function displayEdit(status, k, boolean){
        if(status == 0){
            var idDiv3 = "divEditOrderPromotion"+k+"1";
            var idDiv4 = "divEditOrderPromotion"+k+"2";
            if(boolean == 0){
                $('#'+idDiv3).hide();
                $('#'+idDiv4).show();
            }
            else{
                $('#'+idDiv3).show();
                $('#'+idDiv4).hide();
            }

        }

        if(status == 1){
            var idDiv5 = "divEditProductPromotion"+k+"1";
            var idDiv6 = "divEditProductPromotion"+k+"2";
            if(boolean == 0){
                $('#'+idDiv5).hide();
                $('#'+idDiv6).show();
            }
            else{
                $('#'+idDiv5).show();
                $('#'+idDiv6).hide();
            }
        }
    }
</script>

<script>
    function getSubCategory(id, isEdit){
        var id = id;
//        alert(id);
        if(isEdit != 1){
            $('#hiddenProductPromotion4').val(id);
        }
        else{
            $('#hiddenEditProductPromotion4').val(id);
        }

        if(id != '0'){
            var url = "<?php echo base_url() ?>";
            var dataString = "id="+id;
            $.ajax({
                type: "POST",
                url: url+"admin_category/getSubCategoryNews",
                data: dataString,
                success: function(x){
                    //alert(x);
                    if(isEdit != 1){
                        $('#divChosenCategoryAddPromotionMenu4').html("<b>"+x+"</b>");
                    }
                    else{
                        $('#divChosenCategoryEditPromotionMenu4').html("<b>"+x+"</b>");
                    }
                }
            });
        }
        else{
            if(isEdit != 1){
                $('#divChosenCategoryAddPromotionMenu4').html("Tất cả danh mục");
            }
            else{
                $('#divChosenCategoryEditPromotionMenu4').html("Tất cả danh mục");
            }
        }
    }
</script>



